#define HTTP_ERROR HTTPERROR
#define IO_ERROR IOERROR
#define DLL_ERROR DLLERROR

#include <windows.h>
#include <stdio.h>
#include <io.h>
#include <string>
#include "../headers/FLHook.h"
#include "../headers/plugin.h"
#include "../headers/WebFrontEnd_Tools.h"
#include "../headers/WebFrontEnd_DLLResource.h"
#include "../headers/WebFrontEnd_Http.h"
#include "../headers/WebFrontEnd_Profile.h"
#include "../headers/WebFrontEnd_GameInfo.h"

#include "../CURL/include/curl/curl.h"
#pragma comment(lib, "./CURL/libcurl_imp.lib")

extern vector<string> vDLLPath;

extern bool sSet_PushToServer;
extern string sSet_pvInterface;
extern string sSet_pvServerNickname;
extern string sSet_pvServerPassword;

extern bool sSet_PushToPublic;
extern string sSet_puInterface;
extern string sSet_puServerNickname;
extern string sSet_puServerPassword;

extern string sSet_ServerPort;
extern wstring wsSet_WelcomeMessage;
extern bool bSet_Showoutput;

struct HANDLETHREADPARAMS
{
	enum // Tell program what you want to do
	{
		DONOTHING = 0,
		UPDATEPLAYER = 1,
		UPDATEKILL = 2,
		UPDATETRADE = 3,
		UPDATESYSTEM = 4,
		UPDATEBASE = 5,
		SENDCOMMENT = 6,
		SENDTMSG = 7,
		REPLYTMSG = 8
	} Action;
    int iID; // For iBaseID, iSystemID etc
	wstring wscCharname1; // For Main PlayerName, Do Not use iClientID here or will crash when can't found player by iClientID
	wstring wscIP; // IP For Main Player
	wstring wscCharname2; // For Player 2, Using in trade or kill
	wstring Message; // For Message, Using in TMsg
};

string FeHandle_UpdatePlayer(wstring wscCharname);
string FeHandle_UpdateKill(wstring wscKiller, wstring wscVictim, unsigned int iSystemID);
string FeHandle_UpdateTrade(wstring wscRequester, wstring wscAccepter, unsigned int iSystemID);
string FeHandle_UpdateSystem(wstring wscCharname, unsigned int iSystemID);
string FeHandle_UpdateBase(wstring wscCharname, unsigned int iBaseID);
string FeHandle_SendComment(wstring wscCharname1, wstring wscCharname2, wstring wscMessage);
string FeHandle_SendTMsg(wstring wscCharname, wstring wscMessage);
string FeHandle_ReplyTMsg(wstring wscCharname, unsigned int iMsgID, wstring wscMessage);
void FeHandle(LPVOID p);
HK_ERROR FeHandle_HttpProcess(string scURL, string scData);